import VueRouter from 'vue-router';
import Setting from '@/setting';

// import baseRouters from './modules/base';
//import componentsRouters from './modules/components';
import indexRouters from './modules/index';
import productRouters from "./modules/product";
import warehouseRouters from "./modules/warehouse";
import inventory from "@/router/modules/inventory";
import orderRouters from "./modules/order";
import staffRouters from "./modules/staff";
import agentRouters from "./modules/agent";
import othersRouters from './modules/others';

const env = import.meta.env.MODE || 'development';

// 存放动态路由
export const asyncRouterList = [
  ...indexRouters,
  //...warehouseRouters,
  ...inventory,
  ...orderRouters,
  ...productRouters,
  ...staffRouters,
  ...othersRouters,
  ...agentRouters,
];

// 存放固定的路由
const defaultRouterList = [
  {
    path: '/login',
    name: 'login',
    component: () => import('@/pages/login/index.vue'),
  },
  {
    path: '*',
    redirect: '/product/list',
  },
  ...asyncRouterList,
];

const createRouter = () =>
  new VueRouter({
    //mode: 'history',
    //base: env === 'site' ? '/starter/vue/' : null,
    mode: Setting.routerMode,
    base: Setting.routerBase,
    routes: defaultRouterList,
    scrollBehavior() {
      return { x: 0, y: 0 };
    },
  });

const router = createRouter();

export function resetRouter() {
  const newRouter = createRouter();
  router.matcher = newRouter.matcher; // reset router
}

export default router;
